<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>商品管理</cite></a>
    <a><cite>商品设置</cite></a>
  </div>
</div>

<script>
  var settings_url = 'agent-admin/settings';
</script>
<script type="text/html" template lay-url="{{settings_url}}" lay-done="layui.data.done(d.data)">
  <div class="layui-fluid layui-form">
    <div class="layui-form">
      {{# var settings = d.data }}
      <div class="layui-card">
        <div class="layui-card-header">
          转售设置
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">&nbsp;&nbsp;</div>
          <div class="layui-inline form-required">同一商品取消转售后</div>
          <div class="layui-inline" style="width: 100px">
            <input type="number" autocomplete="off" class="layui-input" lay-verify="required"
                   name="product_resale_cancel_lock_time" value="{{settings.product_resale_cancel_lock_time || 0}}">
          </div>
          <div class="layui-inline">分钟后才可再次发起转售</div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          购买需知
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <div id="purchase_notice">
              {{settings.product_purchase_notice || ''}}
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          转售需知
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <div id="resale_notice">
              {{settings.product_resale_notice || ''}}
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-footer">
          <div class="layui-input-block">
            <input type="button" lay-submit lay-filter="submit_settings" value="保存"
                   class="layui-btn">
          </div>
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.done = function (obj) {
    layui.use(['wangEditor'], function () {
      let form = layui.form
        , admin = layui.admin
        , editor = layui.wangEditor

      //编辑器
      editor.render({
        elem: "#purchase_notice"
        , height: 200
        , name: 'product_purchase_notice'
        , url: 'editor/images'
      });
      editor.render({
        elem: "#resale_notice"
        , height: 200
        , name: 'product_resale_notice'
        , url: 'editor/images'
      });

      // 提交
      form.on('submit(submit_settings)', function (data) {
        let field = data.field;
        console.log(field)
        admin.post(settings_url, field, function () {
          layer.msg('保存成功', {
            offset: '15px'
            , icon: 1
            , time: 1000
          });
        });
      });
    });
  }
</script>
